// 角色管理模块接口
import request from '@/utils/request'
import type { RoleResponseData, RoleData, MenuResponseData } from './type'
enum API {
    // 获取全部职位接口
    ALLROLE_URL = '/admin/acl/role/',
    // 新增职位
    ADDROLE_URL = '/admin/acl/role/save',
    // 更新
    UPDATEROLE_URL = 'admin/acl/role/update',
    // 获取全部的菜单与按钮权限的数据
    ALLPERMISSION_URL = 'admin/acl/permission/toAssign/',
    // 给相应的职位分配权限
    SETPERMISSION_URL = 'admin/acl/permission/doAssign/?',
    // 删除职位
    REMOVEROLE_URL = '/admin/acl/role/remove/'
}
// 获取全部职位接口
export const allRoleAPI = (page: number, limit: number, roleName: string) => request.get<any, RoleResponseData>(API.ALLROLE_URL + `${page}/${limit}/?roleName=${roleName}`)

// 添加与更新职位
export const addOrUpdateRoleAPI = (data: RoleData) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATEROLE_URL, data)
    } else {
        return request.post<any, any>(API.ADDROLE_URL, data)
    }
}

// 获取全部的菜单与按钮权限的数据
export const allMenuListAPI = (roleId: number) => request.get<any, MenuResponseData>(API.ALLPERMISSION_URL + roleId)

// export function allMenuListAPI(roleId: number): MenuResponseData {
//     return request({
//         url: API.ALLPERMISSION + roleId,
//     })
// }

// 给相应的职位分配权限
export const setPermisstionAPI = (roleId: number, permission: number[]) => request.post<any, any>(API.SETPERMISSION_URL + `roleId=${roleId}&permissionId=${permission}`)

// 删除职位
export const removeRoleAPI = (roleId: number) => request.delete<any, any>(API.REMOVEROLE_URL + roleId)